package com.polytech.dao.hibernate;

import java.util.Collection;
import java.util.List;

import com.polytech.beans.Booking;
import com.polytech.beans.Brand;
import com.polytech.beans.Car;
import com.polytech.dao.BookingDao;

public class BookingDaoHibernate extends AbstractHibernateDao implements BookingDao {

	@Override
	public void insert(Booking booking) {
		session.beginTransaction();
			session.save(booking);
		commit();
	}

	@Override
	public Booking select(String key) {
		session.beginTransaction();
			Booking b=(Booking)session.get(Booking.class,key);
		commit();
		return b;
	}

	@Override
	public void remove(Booking booking) {
		session.beginTransaction();
			session.delete(booking);
		commit();
		
	}

	@Override
	public Collection<Car> selecetBookedCars() {
		List<Car>res;
		session.beginTransaction();
			res= (List<Car>) session.createQuery("SELECT b.car FROM Booking as b").list();
		commit();
		return res;
	}

	@Override
	public Collection<Car> selecetNonBookedCars() {
		List<Car>res;
		session.beginTransaction();
			res= (List<Car>) session.createQuery("FROM Car AS c WHERE c NOT IN ( SELECT b.car FROM Booking AS b)").list();
		commit();
		return res;
	}

	
}
